﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChooseList.aspx.cs" Inherits="ZX.WebApp.EditWidows.ChooseList" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls.UserControl"
    TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link type="text/css" rel="stylesheet" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/autocomplete/assets/skins/sam/autocomplete.css" />
    <link href="../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
  
    <link href="/Scripts/JQuery_zTree_v3.3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"
        type="text/css" />
    <link href="/Scripts/JQuery_zTree_v3.3/css/ctrlDemo.css" rel="stylesheet" type="text/css" />
    <link href="/Scripts/Ctrls/Ctrl.css" rel="stylesheet" type="text/css" />



    <script src="../Scripts/Appjs/model.V_CrmDeliverMajorProductLayout.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/autocomplete/autocomplete-min.js"></script>
    
    <script src="../Scripts/EasyUI/js/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/yui.list.button.event.js" type="text/javascript"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.calendar.js" type="text/javascript"></script>
        <script src="/Scripts/JQuery_zTree_v3.3/js/jquery.ztree.core-3.3.js" type="text/javascript"></script>    
    <script src="/Scripts/Ctrls/jquery.TreesSelect.js" type="text/javascript"></script>

    
    <style type="text/css">
        .yui-skin-sam table
        {
            width: 100%;
        }
    </style>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server"> 
    <!-- 工具栏 -->
    <div id="listpage" style="width: 100%">
        <div id="toolbar">
            <div id="div2" style="display: none; padding-bottom: 4px; margin-top: 2px;">
                <table>
                <tr>
                <td style="width:80px">选择部门:<span  style="display: none;"><cc1:DeptList ID="DeptList1" runat="server"></cc1:DeptList></span></td>
                <td><input ctrlType="TreeSelect" entity="V_Dept" type="text" id="Dept"  SelectMode="s" event="_ChangeDept()"/></td>
                </tr>
                </table>
                
            </div>
            <div id="courseTime" style="width: 100%; float: left; margin-top: 2px; margin-bottom: 2px;
                display: none;">
                <label for="myInput" style="float: left">
                    &nbsp;开始时间:</label>
                <input id="txtStartTime" type="text" style="float: left; margin-right: 4px; width: 100px;" />
                <label for="myInput" style="float: left">
                    &nbsp;结束时间:</label>
                <input id="txtEndTime" type="text" style="float: left; margin-right: 4px; width: 100px;" />
            </div>
            <div id="DivproductType" style="width: 100%; float: left; margin-top: 2px; margin-bottom: 2px;
                display: none;">
                <label style="float: left;">
                    &nbsp;产品类型:</label>
                <select id="ProductType" onchange="SelectProductType();" style="float: left; margin-left: 2px;">
                </select>
            </div>
            <div id="myAutoComplete" style="width: 100%; margin-top: 2px;">
                <select id="CustomerType" onchange="ChangeType();" style="float: left; margin-left: 2px;
                    display: none;">
                    <option value="private">我的私海客户</option>
                    <option value="public">公海客户</option>
                </select>
                <select id="TypeName" onchange="ChangeType();" style="float: left; margin-left: 2px;
                    display: none;">
                    <option value="">选择类型</option>
                    <option value="N">N</option>
                    <option value="D">D</option>
                    <option value="F">F</option>
                    <option value="V">V</option>
                    <option value="X">X</option>
                    
                </select>
                <label for="myInput" style="float: left">
                    &nbsp;输入名称:</label>
                <input id="myInput" type="text" style="float: left; margin-right: 4px; width: 210px;" />
                <button id="btnQuery" type="button" value="" onclick="QueryData()" style="float: left;
                    width: 50px; text-align: center">
                    查询</button> 
                    <input type="hidden" value="<% =Order %>" id="queryOrder"/>
                    <input type="hidden" value="<% =Condition %>" id="queryWhere"/>
                <button id="btnCreate" type="button" value="" onclick="CreateDepartment();" style="float: left;
                    width: 60px; text-align: center; display: none">
                    创建公司</button>
                <div id = "divChooseAll" style = "float: right; margin-right: 5px; display: none;">
                    <input type="checkbox" id="chkChooseAll" value="全选" onclick="onChooseAll(this);" />
                    <span>全选</span>
                </div>
            </div>
            <div style="float: left; width: 100%;">
                <span id="tempIds" style="color: Red"></span>
            </div>
        </div>
        <div id="data">
            <div id="json">
            </div>
        </div>
        <div id="pageDiv">
            <div id="pagetotal" style="float: left; height: 25px; padding: 5px; margin-top: 3px;
                width: 100px;">
            </div>
            <div id="page" style="float: left">
            </div>
        </div>
    </div>
    </form>
</body>
<!--  用于加载自定义脚本 -->
<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript"
    language="javascript"></script>
<script type="text/javascript">
    var mDataTable;
    var PageTotal;
    var pageindex = 1;
    var pagesize = 25;
    var editpageFlag = 0; //用于调用AutoUI

    var const_height=0,const_width=0;
    var UserId = "<%=UserId %>";
    var const_entityID = "<% =EntityId %>",
        const_entityName = "<% =EntityName %>",
        const_EditEntity = "<% =EditEntity %>",
        const_condition = "<% =Condition %>",
        const_Order ="<% =Order %>", //排序 
        const_UserId = "<% = UserId %>",       //
        const_UserName = "<% = this.User.LoginName %>",  
        const_customCondition= "<% =Condition %>";
        const_functionId ="59a1b1da-c442-4ddf-b222-df0e871f38bd",//自定义条件

        const_Name="",
        const_TempDeptId="",
        const_ShowCheckBox="<% =ShowCheckBox %>",
        const_DataFields = [<% =DataFields %>],
        const_DataColums = [<% =DataColums %>];
        var topHeight="45";
        var vConstCondition="";
        var vCrmCustomerShow = "";
        var vDeliverConst = "";
        var vCrmCustomerInfoSale="";
        var vCrmPayId="";
        var vDeliverOrderProduct="";
        var vDeptName="";
        var vTradeName="";
        var vCrmDeliverMajorInfo="";
        var vCrmProductLayoutPrint="",vCrmProductLayout="";
        var CrmProductLayoutName="",CrmProductLayoutBeginDate="",
        CrmProductLayoutEndDate="",vCrmCustomerInfoOrderProduct="";

        var const_showChooseAll = false;
        var currDataInfo = [];

    (function () {
                
        //IE支持数组
        if(!Array.indexOf)
        {
            Array.prototype.indexOf = function(el)
            {
	            for (var i=0,n=this.length; i<n; i++)
                {
		            if (this[i] === el)
                    {
		        	    return i;
		            }
	            }
	            return -1;
            }  
         }
        
        $("#txtStartTime").cld();
        $("#txtEndTime").cld();
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        const_height =  Dom.getViewportHeight();
        const_width  = Dom.getViewportWidth();
        if(const_customCondition=="IsOutDepartment=1"){
            var btnCreate=document.getElementById("btnCreate");
            btnCreate.style.display="block";
        }
        if(const_entityName=="V_UserMessage"||const_entityName=="V_UserMq400"||const_entityName=="V_UserEmp"||const_entityName=="DatEmployee" || const_entityName=="V_hrEmployee"){
            var div2=document.getElementById("div2");
            div2.style.display="block";
            topHeight="75";
        }
        if((const_entityName=="V_CrmCustomerShow"&&const_condition!="qudao") ||const_entityName=="V_CrmCustomerShowM"){
           document.getElementById("CustomerType").style.display="block"; 
           topHeight="45";
        }
        if(const_entityName=="V_CrmValuePay"){
           document.getElementById("myAutoComplete").style.display="none"; 
           topHeight="45";
        }
        if(const_entityName=="CrmProductLayout"){
            document.getElementById("courseTime").style.display="block"; 
            topHeight="70";
        }
        if(const_entityName=="V_CrmProductList"){
            document.getElementById("DivproductType").style.display="block"; 
            topHeight="70";
        }
        if(const_entityName=="V_CrmCustomerInfoM"){
           document.getElementById("TypeName").style.display="block"; 
           document.getElementById("divChooseAll").style.display="block"; 
           const_showChooseAll = true;
           topHeight="45";
        }

        if(const_entityName == "V_CrmCustomerInfoProductLayout")
        {   
            //期数权限
            const_functionId = "<% =FunctionID %>";
        }

        LoadProductType();

        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                    { position: 'top', height: topHeight, body: 'toolbar', gutter: '1 1 1 1', scroll: true },
                    { position: 'center', body: 'data', gutter: '1 1 1 1', scroll: true },
                    { position: 'bottom', height: 42, body: 'pageDiv', gutter: '1 1 1 1', scroll: true}
                ]
            });
            layout.render();
        });
    })();

    function LoadProductType(){
        $("#ProductType").append("<option value=''>--选择--</option>");
        var vc = "ClassID='39125FAA-360C-4806-AA80-0E3CF53F3D49' order by Seq";
        YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=DatPhraseDetail&customCondition=" + vc + "", //条件 
            {success: function (res) {
                try {
                    var str = res.responseText;
                    var obj = eval(str);
                    for (var i = 0; i < obj.length; i++) {
                        if (obj[i].PhraseID != undefined || obj[i].PhraseText != undefined) {
                            $("#ProductType").append("<option value='" + obj[i].PhraseID + "'>" + obj[i].PhraseText + "</option>");
                        }
                    }
                }
                catch (e) {
                }
                finally {
                }
            }, failure: function () { }
        });
    }

    var PageTotal;
    var pageindex = 1;
    var pagesize = 25;
    var ids="";
    var names="";
    var mDataTable;
    var CacheData=[];
    var datas=[];
    //刷新数据
    function LoadData2(){
        if(const_entityName=="V_MQOrgBody"||const_entityName=="V_UserMessage"||const_entityName=="V_UserEmp"||const_entityName=="DatEmployee"||const_entityName=="V_UserMq400"){
            const_condition="";
            var obj=document.getElementById("SelectForDept");
            if(obj != null){
                var deptId= obj.value;
                if(const_entityName=="V_UserEmp"){
                    const_customCondition="DeptID='"+deptId+"' and IsExpire=0";
                }
                else{
                    const_customCondition="DeptID='"+deptId+"'";
                }
            }
        }
        if(const_entityName=="V_hrEmployee"){
            const_condition="";
            var obj=document.getElementById("SelectForDept");
            if(obj != null){
                var deptId= obj.value;
                const_customCondition="DeptID='"+deptId+"'";
            }
        }       
        var kid=getPar1("kid");                
        if (const_entityName=="TrCourse"||const_entityName=="DatUser"||kid=="UserIDs"
                ||kid=="IDs"||kid=="obids"||kid=="LoginNames"||kid=="DecisionTel"||kid=="trains") 
        {
            const_ShowCheckBox="true";
        }
        if(!mDataTable){
            BindData();
        }else{
            BulidCondition();
            ReloadData();
            var vurl = "pageindex="+pageindex+"&entity=" + const_entityName + "&r="+Math.random()+"&zip=94089&results=10&output=json"+"&condition="+const_condition+"&customCondition="+const_customCondition+"";
            GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + vurl); 
        }
    }


    function BulidCondition(){
      
        var customCondition = "";
        if(const_entityName=="V_TrActivityCourseExpectation"){
            var condition = "StudentID like '%"+UserId+"%'";
            const_customCondition = encodeURI(condition);
        }
        if(const_entityName=="V_CrmCustomerShow"&&const_condition=="qudao"){
            vCrmCustomerShow="AddUser='"+UserId+"' and IsPrevate='0' and IsValue='1'";
            const_customCondition = encodeURI(vCrmCustomerShow);
        }
        if(const_entityName=="V_CrmCustomerShow"&&const_condition!="qudao"){
            var state=document.getElementById("CustomerType").value;
            if(state=="private"){
                //vCrmCustomerShow = "ID in (select CustomId from CrmPrivateCustom where AddUser='"+UserId+"')";
                // Modified on 09m/05/2014 by zengfei 客户状态依赖相应的表结构进行调整，因此修改读取私海客户相应的条件语句
                vCrmCustomerShow = "ID in (select CustomerID from CrmCustomerDependent where ToUser='"+UserId+"' and CustomerStatus = 1)";
            }else if(state=="public"){
                //condition = "AreaId in (select value from fn_Split((select DeptIds from V_UserEmp where userid='"+UserId+"'),',')) and IsPrevate='0'";
                vCrmCustomerShow="AreaId in (select DeptID from V_CrmUserArea where UserID='"+UserId+"') and IsPrevate='0' and IsValue='1' and Code not like '%CQ%'";
            }
            const_customCondition = encodeURI(vCrmCustomerShow);
        }
        if(const_entityName=="V_CrmCustomerShowM"){
            var state=document.getElementById("CustomerType").value;
            if(state=="private"){
                vCrmCustomerShow = "ID in (select CustomId from CrmPrivateCustom)";
            }else if(state=="public"){
                //condition = "AreaId in (select value from fn_Split((select DeptIds from V_UserEmp where userid='"+UserId+"'),',')) and IsPrevate='0'";
                vCrmCustomerShow="IsPrevate='0' and IsValue='1'";
            }
            const_customCondition = encodeURI(vCrmCustomerShow);
        }
        if(const_entityName=="V_CrmLiveCustomer"){
            const_customCondition = const_condition;
            vDeliverOrderProduct = const_customCondition;
        }
        if(const_entityName=="V_CrmCustomerInfoM"){
        var state=document.getElementById("TypeName").value;
            if(state=="N"||state=="D"||state=="F"||state=="V"||state=="X"){
                vCrmCustomerShow = "TypeName ='"+state+"'";
                const_customCondition = encodeURI(vCrmCustomerShow);
            }else {
                //condition = "AreaId in (select value from fn_Split((select DeptIds from V_UserEmp where userid='"+UserId+"'),',')) and IsPrevate='0'";
               const_customCondition="";
            }
        }
        if(const_entityName=="CrmCustomerOrder"){
            //var condition = "AreaId in (select value from fn_Split((select DeptIds from V_UserEmp where userid='"+UserId+"'),',')) and IsPrevate='0'";
            //condition = condition="AreaId in (select DeptID from V_CrmUserArea where UserID='"+UserId+"') and IsPrevate='0' and IsValue='1'";
            condition="AreaId in (select DeptID from V_CrmUserArea where UserID='"+UserId+"') and IsPrevate='0' and IsValue='1'";
            const_customCondition = encodeURI(condition);
        }
        if(const_entityName=="V_CrmValuePay"){
            condition=getPar1("cid");
            const_customCondition = encodeURI(condition);
        }
        
        if(const_entityName=="V_CrmCustomerInfoSale"){   
            if(const_condition=="crmlinkman"){                
                const_condition= "(LectorUser='"+UserId+"' or CustomeerMgr='"+UserId+"')";
               // const_condition= "(1=1)";
                vCrmCustomerInfoSale=const_condition;
                const_customCondition=encodeURI(const_condition);
            } else if(const_condition=="crmvalue"){ 
                const_condition= "ID in (select distinct t.ID  from V_CrmCustomerInfoSale t INNER JOIN V_CrmValuePay cp on t.ID=cp.CustomerId INNER JOIN CrmPay C ON cp.PayId=c.ID  and c.State='86B67A2C-8DF8-417C-B70D-6D54969B812D' WHERE (LectorUser='"+UserId+"' or CustomeerMgr='"+UserId+"') and IsValue=1)"  
                //const_condition = "(LectorUser='"+UserId+"' or CustomeerMgr='"+UserId+"') and ID in (select  CustomerId from V_CrmValuePay where PayId in(select ID from CrmPay where State='86B67A2C-8DF8-417C-B70D-6D54969B812D')) and IsValue=1";
                vCrmCustomerInfoSale=const_condition;
                const_customCondition=encodeURI("");
            } else if(const_condition=="crmqichu"){
                const_condition="";
                vCrmCustomerInfoSale=const_condition;
                const_customCondition=encodeURI(vCrmCustomerInfoSale);
            } else {
                if(const_condition==""){
                    vCrmCustomerInfoSale = "(LectorUser='"+UserId+"' or CustomeerMgr='"+UserId+"') and IsValue=1";
                    const_customCondition=encodeURI(vCrmCustomerInfoSale);
                }
            }
        }
        if(const_entityName=="V_CrmCustomerInfoDeliver"){
            var condition = "TypeID<>'5E50217A-414E-46D5-89BC-348AD0145FFC' and (StateID='AF73673F-9FEC-4D14-ACFD-B0FCE08D6FFA' or StateID='EDA4FAA9-8544-494C-BF1C-02662E1078A6' or StateID='BDDCAF31-98D4-423A-9275-9288F85E2847')";
            if(const_customCondition==""){  
                const_customCondition = encodeURI( vDeliverConst + " and " + condition);
            }else{
                const_customCondition = encodeURI(const_customCondition + " and " + condition);
                vDeliverConst=const_customCondition;
            }
        }
        if(const_entityName=="V_DeliverOrderProduct"){
            const_customCondition = const_condition;
            vDeliverOrderProduct = const_customCondition;
        }
        if(const_entityName=="V_CrmUserArea"){
            const_customCondition=const_condition;
            vDeptName=const_customCondition;
        }
        if(const_entityName=="V_CrmUserAreaAll"){
            const_customCondition=const_condition;
            vDeptName=const_customCondition;
        }
        if(const_entityName=="DatPhraseDetail"){
            const_customCondition=const_condition;
            vTradeName=const_customCondition;
        }
        if(const_entityName=="V_CrmDeliverMajorInfo"){
            const_customCondition=const_condition;
            vCrmDeliverMajorInfo=const_customCondition;
        }
        if(const_entityName=="CrmProductLayout"){
            const_customCondition=const_condition;
            vCrmProductLayout=const_customCondition;
        }
        if(const_entityName=="V_CrmProductLayoutPrint"){
            const_customCondition=const_condition;
            vCrmProductLayoutPrint=const_customCondition;
        }
        if(const_entityName=="V_CrmCustomerInfoOrderProduct"){
            const_customCondition=const_condition;
            vCrmCustomerInfoOrderProduct=const_customCondition;
        }
        if(const_entityName=="V_CrmCustomerInfoOrderTK"){
            const_customCondition=const_condition;
            vCrmCustomerInfoOrderProduct=const_customCondition;
        }
        if(const_entityName=="V_CrmProductList"||const_entityName=="V_DatCustomerBank"){
            const_customCondition=const_condition;
            vConstCondition=const_customCondition;
        }
        
        if(const_entityName=="V_CrmChoseTeacher"){
            const_customCondition=const_condition;
            vConstCondition=const_customCondition;
        }
        if(const_entityName=="V_CrmCustomerShow"&&const_condition=="qudao"){
            const_condition="";
        }
        if(const_entityName=="V_CrmCustomerInfoProductLayout")
        {
            const_customCondition=const_condition;
            vConstCondition=const_customCondition;
        }
    }
    function ReloadData(){
        var requestStr = "pagesize=" + pagesize + "&pageindex=" + pageindex + "&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + const_customCondition + "&condition=" + const_condition;
        GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + requestStr);
        mDataTable.requery(requestStr);
        fnCreateChkAllCheckBox();
    }

    //数据绑定
    function BindData() {
        YAHOO.example.XHR_JSON = function() {
            var formatUrl = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
            };   
            var formatRating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = (sData === null) ? "N/A" : YAHOO.util.Number.format(sData);
            };
            var myColumnDefs = const_DataColums;
            var myDataSource = new YAHOO.util.DataSource("../Extend/AjaxData/JSONList.aspx?");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            myDataSource.connXhrMode = "queueRequests";
            myDataSource.responseSchema = {
                resultsList: "rows",
                fields: myColumnDefs
            };
            BulidCondition();

            var initRequestUrl = "pageindex="+pageindex+"&entity=" + const_entityName + "&order="+const_Order+"&r="+Math.random()+"&zip=94089&results=10&output=json&condition="+const_condition+"&customCondition="+const_customCondition+"";
            if(const_entityName == "V_CrmCustomerInfoProductLayout")
            {
                initRequestUrl = initRequestUrl + "&functionId=" + const_functionId;
                parent._fn('','加载数据中, 请稍等...');
            }
            this.myDataTable = new YAHOO.widget.ScrollingDataTable("json",const_DataFields ,
                    myDataSource,
                    {   
                        initialRequest:initRequestUrl,
                        selectionMode:"single"  //, 
                        //height: (const_height - 125) + "px",
                        //width: "500px"
                        //width: (const_width-25 ) + "px"
                    });
            mDataTable =this.myDataTable;   
            var mySuccessHandler = function() {
                this.set("sortedBy", null);
                this.onDataReturnAppendRows.apply(this,arguments);
            };
            var myFailureHandler = function() {
                this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
                this.onDataReturnAppendRows.apply(this,arguments);
            };
            var callbackObj = {
                success : mySuccessHandler,
                failure : myFailureHandler,
                scope : myDataTable
            };
            mDataTable = this.myDataTable;
            var vurl = "pageindex="+pageindex+"&entity=" + const_entityName + "&r="+Math.random()+"&zip=94089&results=10&output=json"+"&condition="+const_condition+"&customCondition="+const_customCondition+"";
            if(const_entityName == "V_CrmCustomerInfoProductLayout")
            {
                vurl = vurl + "&functionId=" + const_functionId;
            }
            GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + vurl); 
            //调用自定义点击行的方法
            
            var dbClick= function(){
              
                var isChooseAll = document.getElementById("chkChooseAll").checked;                
                var recordID = mDataTable.getSelectedRows()[0];
                record = mDataTable.getRecord(recordID);
                var kid=getPar1("kid");
                var t=0;            
                if(kid=="UserIDs"){
                    kid="UserID";
                    t=1;
                }else if(kid=="LoginNames"){ 
                    kid="LoginName";
                    t=1;
                }else if(kid=="IDs"){ //mqmids
                    kid="ID";
                    t=1;
                }else if(kid=="obids"){ 
                    kid="obid";
                    t=1;
                }else if(kid=="trains"){
                    kid="MajorStudentID";
                    t=1;
                }
                var kname=getPar1("kname"); 
                if(const_ShowCheckBox=="true" && record.getData("iSun_Selected") != undefined)
                {
                    if(ids.indexOf(record.getData(kid))==-1 || names.indexOf(record.getData(kname)))
                    {
                        if(const_showChooseAll)
                        {
                            ChooseDataShow(record, record.getData(kid), record.getData(kname), record.getData("iSun_Selected"), isChooseAll);
                        }
                        else if(record.getData("iSun_Selected"))
                        {
                            ids+=record.getData(kid)+",";
                            names+=record.getData(kname)+","; 
                        }
                    }
                    else
                    {
                        if(!record.getData("iSun_Selected"))  
                        { 
                            ids=ids.replace(record.getData(kid)+",",''); 
                            names=names.replace(record.getData(kname)+",",'');
                        }
                    }

                    /* old
                    if(ids.indexOf(record.getData(kid))==-1 || names.indexOf(record.getData(kname)))
                    {
                        if(record.getData("iSun_Selected")) 
                        { 
                            ids+=record.getData(kid)+",";
                            names+=record.getData(kname)+","; 
                        }
                    } 
                    else
                    {
                        if(!record.getData("iSun_Selected"))  
                        { 
                            ids=ids.replace(record.getData(kid)+",",''); 
                            names=names.replace(record.getData(kname)+",",'');
                        }
                    }*/
                }
                else
                {
                    if(t==0){
                        ids=record.getData(kid)+","; 
                        if(kname=="CourseLayoutNames") {
                            names=record.getData("BeginDate")+"-- "+record.getData("EndDate")+" "+record.getData("Place")+",";
                        }else if(kname=="V_CrmProductListCaption"){
                            names=record.getData("Caption");
                        }else{
                            names=record.getData(kname)+",";      
                        }
                    }
                }
                if(const_entityName=="CrmProductLayout"){
                    CrmProductLayoutName=record.getData("CourseLayoutName");
                    CrmProductLayoutBeginDate=record.getData("BeginDate");
                    CrmProductLayoutEndDate=record.getData("EndDate");
                }

                SelDataShow();

                /* old
                document.getElementById("tempIds").innerHTML="";
                if(names.length>0){
                    document.getElementById("tempIds").innerHTML="&nbsp;您已选择下列数据："+names.substring(0,names.length-1);
                }else{
                    alert("请勾中一条记录");    
                }*/

                const_Name=kname;
                if(const_entityName=="V_CrmPayByCid"){
                    ids=record.getData("DeptID")+"@"+ids;
                }
            }
	        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
	        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
            this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow); 
            this.myDataTable.subscribe("rowClickEvent", dbClick);         
            this.myDataTable.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });

        //支持获取记录总数、全选设置
        this.myDataTable.handleDataReturnPayload = function(oRequest,oResponse,oPayload)
        {         
            if(const_showChooseAll == true)
            {
                RefreshShowChooseRows();
            }
        }

        this.myDataTable.selectRow(this.myDataTable.getTrEl(0)); 
        if(const_entityName=="V_CrmDeliverHrTerm"){
            hideColYc();
        }else{
            hideCol();
        }
        fnCreateChkAllCheckBox();
        if(const_ShowCheckBox=="false"){
            hideCheckBox();
        }else{}
        }();
    }
    var fnFormatCustomerCode = function (elCell, oRecord, oColumn, sData) {
         elCell.innerHTML = sData;
    }
    //隐藏/栏位
    function hideColYc(){ 
        mDataTable.hideColumn(parseInt(0));
        mDataTable.hideColumn(parseInt(3));
        mDataTable.hideColumn(parseInt(4));
        mDataTable.refreshView(); 
    };
    function hideCol(){
        mDataTable.hideColumn(parseInt(0));
        mDataTable.refreshView();
    };
    function hideCheckBox(){ 
        mDataTable.hideColumn(parseInt(1)); 
        mDataTable.refreshView(); 
    };
    YAHOO.util.Event.addListener(window, "load", LoadData2);
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {  
	    var handleCancel = function() {
		    this.cancel();
	    };
	    var handleSuccess = function(o) {
		    var response = o.responseText;
		    response = response.split("<!")[0];
		    document.getElementById("resp").innerHTML = response;
	    };
	    var handleFailure = function(o) {
		    alert("Submission failed: " + o.status);
	    };
		resize.on("startResize", function (args) {
			if (this.cfg.getProperty("constraintoviewport")) {
				var D = YAHOO.util.Dom;

				var clientRegion = D.getClientRegion();
				var elRegion = D.getRegion(this.element);

				resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
				resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
			} else {
				resize.set("maxWidth", null);
				resize.set("maxHeight", null);
			}

		}, YAHOO.example.container.dialog1, true);
		resize.on("resize", function (args) {
			var panelHeight = args.height;
			this.cfg.setProperty("height", panelHeight + "px");
		}, YAHOO.example.container.dialog1, true);
    });
   function ChooseInfo(){
        //debugger
        //是否多选
        /*if(const_ShowCheckBox!="false"){
            var list = this.mDataTable.getRecordSet()._records;
            var elist = [];
            dl = [];
            for (var i = 0; i < list.length; i++) {
                //this.getRecordSet()._records[0]._oData["BarItem"]
                if (list[i]._oData["iSun_Selected"] == true) {
                    elist.push(list[i]._oData[const_entityID]);
                    dl.push(list[i]._oData[const_Name]); //获取行ID；
                }
            }
            if (elist.length >0)
            {
               ids="";names="";
               ids=elist.join(",");
               names=dl.join(",");
               parent._fn("","");
               parent._fn(ids,names);
            }
        }
        else*/
        //{

        var typeName = document.getElementById("TypeName").value;
        var bChecked = document.getElementById("chkChooseAll").checked;
        if(const_showChooseAll && bChecked && typeName != "")
        {
            var url = "../Extend/AjaxData/JSONList.aspx?entity=V_CrmCustomerInfoMessage&pageindex=0&output=json&r=" + Math.random() + "&condition=&customCondition=TypeName='"+ typeName+"'";
            $.ajax({
                url: url,
                type: "GET",
                timeout: 10000,
                success: function(data)
                {
                    var sPharse = "";
                    var objData = eval("("+data+")");
                    var currRow = null;

                    for(var i = 0; i<objData.total; i++)
                    {
                        currRow = objData.rows[i];
                        if(names.indexOf(currRow.Mobile)==-1)
                        {
                            sPharse += currRow.Mobile + ',';
                        }
                    }
                    parent._fn('', sPharse.length == 0 ? sPharse : sPharse.substring(0, sPharse.length-1));
                },
                error: function(error)
                {
                    parent._fn('', '');
                    alert("加载数据失败!");
                }
            });

            parent._fn('','加载数据中, 请稍等...');
            return;
        }

        parent._fn("","");
        names=names.substring(0,names.length-1); 
        if (const_entityName=="V_CrmPayByCid"){
            parent._fn(ids,names);
        }else{
            ids=ids.substring(0,ids.length-1);
            parent._fn(ids,names);
        }
        //}
   }

   var _ChangeDept=function(){
       //debugger
       var deptid = $("#Dept").attr("SValue");
       $("#SelectForDept").val(deptid);
       ChangeDept();
   }
   var ChangeDept=function(){
        //ReloadData();
        LoadData2();
   }
   var getConst_condition=function(selectName){
      var obj=document.getElementById("myInput");
      if(obj.value!=""){
            var names = obj.value.split(",");
            var str = "";
            var selectNames=selectName.split(',');
            for(var j=0;j<selectNames.length;j++){
                for (var i = 0; i < names.length; i++) {
                    if (i != 0) {
                        str += " or ";
                    }
                    str += selectNames[j] + " like '%" +names[i] + "%' ";
                }
            }
            return str;
       }
       else{
         return "";
       }
   }
   var i=0;
   var QueryData = function(){
        switch(const_entityName){
            case "DatUser":
                const_condition=encodeURI(getConst_condition("UName"));
                //const_condition=encodeURI("UName like '%"+obj.val()+ "%'" );
                break;
            case "V_UserEmp":
                var vName=getConst_condition("Name");
                var _qorder=document.getElementById("queryOrder").value;
                var _qwhere=document.getElementById("queryWhere").value;

                if(vName!=""){
                    const_condition=" and "+encodeURI(getConst_condition("Name")+" and  IsExpire=0");
                } 
                if(_qwhere=="")
                  const_condition="1=1 "+const_condition;
                else 
                  const_condition=_qwhere +const_condition;  

                 const_Order=(_qorder!="")?_qorder:const_Order;
                
                //const_condition=encodeURI("UName like '%"+obj.val()+ "%'" );
                break;
            case "V_UserMq400":
                var vName=getConst_condition("Name");
                if(vName!=""){
                    const_condition=encodeURI(getConst_condition("Name")+" and  IsExpire=0");
                }
                //const_condition=encodeURI("UName like '%"+obj.val()+ "%'" );
                break;
            case "V_UserMessage":
                var vName=getConst_condition("Name");
                if(vName!=""){
                    const_condition=encodeURI(getConst_condition("Name")+" and  IsExpire=0");
                }
                //const_condition=encodeURI("UName like '%"+obj.val()+ "%'" );
                break;
            case "V_hrEmployee": //选择职员
                var vName=getConst_condition("CName");
                if(vName!=""){
                    const_condition=encodeURI(getConst_condition("CName"));
                }
                break;       
            case "V_TrCustomer":
                //const_funcitonID ="05f5a411-53de-4c54-95d7-798e67092c3a";
                const_condition=encodeURI(getConst_condition("Deptname"));
                //const_condition=encodeURI("CustomerName like '%"+obj.val()+ "%'" );
                break;
            case "TrCustomer":
                const_condition=encodeURI(getConst_condition("Deptname"));
                //const_condition=encodeURI("CustomerName like '%"+obj.val()+ "%'" );
                break;
            case "TrCourse":
                const_condition=encodeURI(getConst_condition("CourseName"));
                //const_condition=encodeURI("CourseName like '%"+obj.val()+ "%'" );
                break;
            case "DatDepartment":
                const_condition=encodeURI(getConst_condition("DeptName"));
                //const_condition=encodeURI("DeptName like '%"+obj.val()+ "%'" );
                break;
            case "V_CrmLiveCustomer":
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vDeliverOrderProduct;
                }else {
                     const_condition=vDeliverOrderProduct+" and "+encodeURI(getConst_condition("CustomerName"));
                }
                break;
            case "DatEmployee":
                const_condition=encodeURI(getConst_condition("[Name]"));
                break;
            case "V_MQModel":
                const_condition=encodeURI(getConst_condition("Mtitle"));
                break;
            case "V_MmsMessage":
                const_condition=encodeURI(getConst_condition("mtitle"));
                break;
            case "V_MQOrgBody":
                const_condition=encodeURI(getConst_condition("Ming"));
                break;
            case "V_CrmUserArea": 
                var vName = getConst_condition("DeptName");
                if(vName==""){
                    const_condition=vDeptName;
                }else{
                    const_condition=vDeptName+" and "+encodeURI(getConst_condition("DeptName"));
                }
                break;
case "V_CrmUserAreaAll": 
                var vName = getConst_condition("DeptName");
                if(vName==""){
                    const_condition=vDeptName;
                }else{
                    const_condition=vDeptName+" and "+encodeURI(getConst_condition("DeptName"));
                }
                break;

            case "DatPhraseDetail": 
                var vName = getConst_condition("PhraseText");
                if(vName==""){
                    const_condition=vTradeName;
                }else{
                    const_condition=vTradeName+" and "+encodeURI(getConst_condition("PhraseText"));
                }
                break;
            case "V_CrmPayByCid": //缴款单选择查询
                if(i==0){
                    vCrmPayId = const_condition;
                    i++;
                }
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmPayId;
                }else{
                    const_condition=vCrmPayId+" and "+encodeURI(getConst_condition("CustomerName"));
                }
                break;
            case "CrmProductLayout": 
                var const_startTime="";const_endTime="",const_couseName="";
                var startTime=document.getElementById("txtStartTime").value;
                var endTime=document.getElementById("txtEndTime").value;
                var couseName=getConst_condition("CourseLayoutName");

                var _qorder=document.getElementById("queryOrder").value;
                var _qwhere=document.getElementById("queryWhere").value;

                if(startTime!=""){
                    const_startTime=" and "+encodeURI("BeginDate >= '"+startTime+"'");
                }
                if(endTime!=""){
                    const_endTime=" and "+encodeURI("EndDate <= '"+endTime+"'");
                }
                if(couseName!=""){
                    const_couseName=" and "+encodeURI(getConst_condition("CourseLayoutName"));
                }
                if(_qwhere=="")
                  const_condition="1=1 "+const_couseName+const_startTime+const_endTime;
                else 
                  const_condition=_qwhere+const_couseName+const_startTime+const_endTime;
                  
                const_Order=(_qorder!="")?_qorder:const_Order;
                
                break;
            case "V_CrmCustomerRelation": //客户关系列表选择查询
                const_condition=encodeURI(getConst_condition("CustomerName"));
                break;
            case "V_DeliverOrderProduct": 
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vDeliverOrderProduct;
                }else {
                     const_condition=vDeliverOrderProduct+" and "+encodeURI(getConst_condition("CustomerName"));
                }
                break;
            case "V_CrmCustomerShow": 
            case "V_CrmCustomerShowM"://约场订单选择查询
                //debugger
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmCustomerShow;
                }else{
                    const_condition=vCrmCustomerShow+" and "+encodeURI(getConst_condition("CustomerName"));
                }
                break;
            case "V_CrmCustomerInfoM"://消息客户查询
                //debugger
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmCustomerShow;
                }else{
                    const_condition=vCrmCustomerShow+" and "+encodeURI(getConst_condition("CustomerName"));
                }
                break;
            case "V_CrmCustomerInfoSale": //销售订单选择查询
                //debugger
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmCustomerInfoSale;
                }else{
                if(vCrmCustomerInfoSale==""){
                const_condition= encodeURI(getConst_condition("CustomerName"));
              
                }else{
                    const_condition= (vCrmCustomerInfoSale)+" and "+encodeURI(getConst_condition("CustomerName"));
                    }
                }
                break;
            case "V_CrmCustomerInfoDeliver": //交付单选择查询
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vDeliverConst;
                }else{
                    const_condition=vDeliverConst+" and "+encodeURI(vName);
                }
                break;
            case "DatPost":
                const_condition=encodeURI(getConst_condition("PostName"));
                break;
            case "V_CrmDeliverMajorInfo":
                var vName = getConst_condition("ClassName");
                if(vName==""){
                    const_condition=vCrmDeliverMajorInfo;
                }else{
                    const_condition=vCrmDeliverMajorInfo+" and "+encodeURI(getConst_condition("ClassName"));
                }
                break;
            case "V_CrmProductLayoutPrint":
                var vName = getConst_condition("CourseLayoutName");
                if(vName==""){
                    const_condition=vCrmProductLayoutPrint;
                }else{
                    const_condition=vCrmProductLayoutPrint+" and "+encodeURI(getConst_condition("CourseLayoutName"));
                }
                break;
            case "V_CrmCustomerInfoOrderProduct":
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmCustomerInfoOrderProduct;
                }else{
                    const_condition=vCrmCustomerInfoOrderProduct+" and "+encodeURI(vName);
                }
                break;
            case "V_CrmCustomerInfoOrderTK":
                var vName = getConst_condition("CustomerName");
                if(vName==""){
                    const_condition=vCrmCustomerInfoOrderProduct;
                }else{
                    const_condition=vCrmCustomerInfoOrderProduct+" and "+encodeURI(vName);
                }
                break;
            case "V_CrmProductList":
                var vType=$("#ProductType").val();
                var vName=getConst_condition("Caption");

                var _qorder=document.getElementById("queryOrder").value; 

                if(vType==""||vType=="00000000-0000-0000-0000-000000000000"){
                    const_condition=vConstCondition;
                }else{
                    const_condition=((vConstCondition=="")?"":" and ")+" TypeId='"+vType+"'";
                }
                if(vName!=""){
                    const_condition+=((const_condition=="")?"":" and ")+encodeURI(vName);
                } 
                  
                const_Order=(_qorder!="")?_qorder:const_Order;
                break;
            case "V_DatCustomerBank":
                var vName=getConst_condition("PhraseText");
                if(vName==""){
                    const_condition=vConstCondition;
                }else{
                    const_condition=vConstCondition+" and "+encodeURI(vName);
                }
                break;
            case "V_CrmChoseTeacher":
                var vName=getConst_condition("CName");
                if(vName==""){
                    const_condition=vConstCondition;
                }else{
                    const_condition=vConstCondition+" and "+encodeURI(vName);
                }
                break;
            case "V_CrmCustomerInfoProductLayout":
                var vName=getConst_condition("CustomerName");
                if(vName==""){
                    const_condition = vConstCondition;
                }else{
                    const_condition = (vConstCondition =="") ? " " + encodeURI(vName) : vConstCondition + " and "+encodeURI(vName);
                }
                break;
            default:
                break;
        }
        const_customCondition="";
        pageindex=1;
        //document.getElementById("tempIds").innerHTML=""; //ids="";
        ReloadData();
        setTimeout(fnCreateChkAllCheckBox,10);
    }
    var ChangeType = function(){
        const_condition="";
        BindData();
        
        if(const_showChooseAll)
        {
            document.getElementById("chkChooseAll").checked = false;
            currDataInfo.splice(0, currDataInfo.length);
            ids = "";
            names = "";
            SelDataShow();
        }
    }
    var CreateDepartment = function () {
        var name = document.getElementById("myInput").value;
        var url = "";
        if (name == "") {
            alert("请先输入需要创建的部门名称");
        }
        else {
            var url = "../Extend/AjaxData/DataProcessin.aspx?action=Save&entity=DatDepartment&deptName="+encodeURI(name)+"";
            YAHOO.util.Connect.asyncRequest('POST', url, { success: function (res) {
                var inventory;
                try {
                    inventory = JSON.parse(res.responseText);
                    if (inventory == 1) {
                        alert("创建公司成功!");
                        LoadData2();
                    } else {
                        alert("保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
                failure: function (error) {
                    alert("读取菜单数据错误：" + error.statusText);
                }
            }, null);
        }
    }
    var SelectProductType = function(){
        const_customCondition="";
        var vType=$("#ProductType").val();
        var vName=getConst_condition("Caption");
        if(vType==""||vType=="00000000-0000-0000-0000-000000000000"){
            const_condition=vConstCondition;
        }else{
            const_condition=vConstCondition+" and TypeId='"+vType+"'";
        }
        if(vName!=""){
            const_condition+=" and "+encodeURI(vName);
        }
        ReloadData();
    }

    //用于数据刷新
    YAHOO.widget.DataTable.prototype.requery = function(newRequest) {
	    var ds = this.getDataSource();
	    if (ds instanceof YAHOO.util.LocalDataSource) {
		    ds.liveData = newRequest;
		    ds.sendRequest("",
			    {
				    success: this.onDataReturnInitializeTable,
				    failure: this.onDataReturnInitializeTable,
				    scope: this
			    }
		    );
	    } else {
		    ds.sendRequest(
			    (newRequest === undefined?this.get('initialRequest'):newRequest),
			    {
				    success: this.onDataReturnInitializeTable,
				    failure: this.onDataReturnInitializeTable,
				    scope: this
			    }
		    );
	    }
    };
    // 获取最新的总数
    var GetTotal = function (url) {
        YAHOO.util.Connect.asyncRequest('POST', url, {
            success: function (res) {
                var o = eval(res.responseText);
                SetPaging(o[0].total);
                if (document.getElementById("pagetotal") != null) {
                    document.getElementById("pagetotal").innerHTML = "<b>共<font color=\"red\">" + o[0].total + "</font>笔记录</b>";
                }
                if (o[0].total == 0) {
                    setTimeout('mDataTable.showTableMessage("没有数据", "没有数据")', 2000);
                }
            },
            failure: function (error) {
            }
        }, null);
    }
    // 分页方法
    var SetPaging = function (total) {
        //debugger
        var Ex = YAHOO.namespace('example');
        Ex.handlePagination = function (state) {
            //debugger
            pageindex = state.page;
            pagesize = Ex.Config.rowsPerPage;
            var requestStr = "pagesize=" + Ex.Config.rowsPerPage + "&pageindex=" + pageindex + "&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + const_customCondition + "&condition=" + const_condition;
            myDataTable.requery(requestStr);
            Ex.paginator.setState(state);
        };
        Ex.Config = {
            rowsPerPage: 25,
            firstPageLinkLabel: "第一页",
            lastPageLinkLabel: "尾页",
            previousPageLinkLabel: "上一页",
            nextPageLinkLabel: "下一页",
            totalRecords: total,
            containers: 'page'
        };
        Ex.paginator = new YAHOO.widget.Paginator(Ex.Config);
        Ex.paginator.subscribe('changeRequest', Ex.handlePagination);
        Ex.paginator.render();
    }
var fnCreateChkAllCheckBox = function () {
    if ((document.getElementById("chkAll")) == null) {
        var e1 = window.document.getElementById("yui-dt5-th-iSun_Selected");
        if (e1 == null) {
            e1 = window.document.getElementById("yui-dt5-th-iSun_Selected");
        }
        if (e1 == null) {
            return;
        }
        if (typeof (e1) != "undefined") {
            var in1 = e1.firstChild;
            var el = document.createElement("input");
            el.setAttribute("type", "checkbox");
            el.setAttribute("id", "chkAll");
            el.setAttribute("onclick", "fnChkAll()");
            el.setAttribute("style", "margin-left:0px;margin-top:0px;z-index:200")
            if(typeof(in1)!="undefined" && in1!=null) 
            {in1.insertBefore(el);}
        }
    }
}

var fnChkAll = function () {
    var ck = document.getElementsByTagName("input");
    for (var i = 0; i < ck.length; i++) {
        if (ck[i].getAttribute("type") == "checkbox" & ck[i].id != "checkAndOr") {
            ck[i].checked = document.getElementById("chkAll").checked;
            if (mDataTable._oRecordSet._records[i] != undefined) {
                mDataTable._oRecordSet._records[i]._oData.iSun_Selected = ck[i].checked;
            }
        }
    }
    if(document.getElementById("chkAll").checked){
        ids="";
        names="";
        for(var i =0 ;i< mDataTable._oRecordSet._records.length;i++)
        {                                                                
            if (mDataTable._oRecordSet._records[i] != undefined) {
                mDataTable._oRecordSet._records[i]._oData.iSun_Selected = ck[i].checked;
                if(getPar1("entity")=="V_CrmCustomerShowM"){
                    ids+=mDataTable._oRecordSet._records[i]._oData.UserID+",";
                    names+=mDataTable._oRecordSet._records[i]._oData.Mobile+",";
                }else if(getPar1("entity")=="V_CrmCustomerInfoM"){
                    ids+=mDataTable._oRecordSet._records[i]._oData.UserID+",";
                    names+=mDataTable._oRecordSet._records[i]._oData.Mobile+",";
                }
                else if(getPar1("entity")=="V_CrmValuePay"){
                    ids+=mDataTable._oRecordSet._records[i]._oData.ID+",";
                    names+=mDataTable._oRecordSet._records[i]._oData.Caption+",";
                }else if(getPar1("entity")=="V_UserEmp"){
                    if (getPar1("kid")=="LoginNames") {
                        ids+=mDataTable._oRecordSet._records[i]._oData.LoginName+",";
                    }else{
                        ids+=mDataTable._oRecordSet._records[i]._oData.UserID+",";
                    }
                    names+=mDataTable._oRecordSet._records[i]._oData.Name+",";
                }else if(getPar1("entity")=="V_CrmDeliverMajorInfo"){
                    ids+=mDataTable._oRecordSet._records[i]._oData.MajorStudentID+",";
                    names+=mDataTable._oRecordSet._records[i]._oData.ClassName+",";
                }
               
                else{
                    ids+=mDataTable._oRecordSet._records[i]._oData.UserID+",";
                    names+=mDataTable._oRecordSet._records[i]._oData.Mobile+",";
                }
            }
            document.getElementById("tempIds").innerHTML="";
            if(names.length>0){
                document.getElementById("tempIds").innerHTML="&nbsp;您已选择下列数据："+names.substring(0,names.length-1);
            }else{
                alert("请勾中一条记录");    
            }
        }
    }else{
        document.getElementById("tempIds").innerHTML="";
        ids="";
        names="";
    }
}

    //数据显示
    function SelDataShow()
    {
        var isChooseAll = document.getElementById('chkChooseAll').checked;
        var strDateShow = "";

        if(isChooseAll == false)
        {
            strDateShow =  names.length > 0 ? "&nbsp;您已选择下列数据："+ names.substring(0, names.length-1) : "";
        }
        else
        {
            strDateShow = names.length > 0 ? "&nbsp;您已选择下列数据："+ (currDataInfo.length > 0 ? names.substring(0, names.length-1) : names) : "";
        }

        document.getElementById("tempIds").innerHTML = strDateShow;
    }

    //是否全选
    function onChooseAll(object)
    {
        var tdClassName = "." + this.mDataTable.getColumn("iSun_Selected")._elTh.className.replace(" ",".");
        var chkSelector = $(this.mDataTable.getBody()).find(tdClassName + " :checkbox");
        var isChecked = object.checked;
        var sTypeName = document.getElementById("TypeName").value;

        var oList = mDataTable.getRecordSet()._records;
        var count = oList.length;
        for(var i=0; i<count; i++)
        {
            oList[i].setData("iSun_Selected", isChecked);
        }

        $(chkSelector).attr("checked", isChecked);
        mDataTable.refreshView();

        currDataInfo.splice(0, currDataInfo.length);
        ids = "";
        names = isChecked ? (sTypeName=="" ? "" : ("[" + document.getElementById("TypeName").value + "类全选]")) : "";

        SelDataShow();
    }

    //刷新选择行
    function RefreshShowChooseRows()
    {
        var isChooseAll = document.getElementById('chkChooseAll').checked;
        var isChooseRow = false;
        var tdClassName = "." + this.mDataTable.getColumn("iSun_Selected")._elTh.className.replace(" ",".");

        var oList = mDataTable.getRecordSet()._records;
        var count = oList.length;
        var oData = '';
        var record = '';
        for(var i=0; i<count; i++)
        {
            record = oList[i];
            oData = record._oData['Mobile'];

            if(isChooseAll)
            {
                isChooseRow = currDataInfo.length == 0 ? true : (currDataInfo.indexOf(oData) == -1);
            }
            else
            {
                isChooseRow = currDataInfo.length == 0 ? false : (currDataInfo.indexOf(oData) != -1);
            }
            //isChooseRow = isChooseAll ? (currDataInfo.indexOf(oData) == -1) : (currDataInfo.indexOf(oData) != -1);                        
            record.setData("iSun_Selected", isChooseRow);
            $('#'+ record._sId + " "+ tdClassName + " :checkbox").attr("checked", isChooseRow);
        }

        mDataTable.refreshView();
    }

    //单行选择[isChooseAll: 是否全选, isChecked: 记录是否已选]
    function ChooseDataShow(record, sKid, sKname, isChecked, isChooseAll)
    {        
        var mobile = record._oData["Mobile"];
        var iIndex = currDataInfo.length == 0 ? -1 : currDataInfo.indexOf(mobile);

        //两种情况
        //1、全选(currDataInfo为【isChecked == 'false'】)
        //2、非全选(currDataInfo为【isChecked == 'true'】)

        if(isChooseAll)
        {
            if(isChecked)
            {
                if(iIndex > -1)
                {
                    currDataInfo.splice(iIndex, 1);
                    if(currDataInfo.length == 0)
                    {   
                        ids = "";
                        names = "[" + document.getElementById("TypeName").value + "类全选]";
                    }
                }

                ids = ids.replace(sKid + "," ,''); 
                names = names.replace(sKname + "," ,'');
            }
            else
            {
                if(iIndex == -1)
                {
                    if(currDataInfo.length == 0)
                    {
                        names += "(过滤-";
                    }
                    currDataInfo.push(mobile);

                    ids += sKid + ",";
                    names += sKname + ","; 
                }
            }
        }
        else
        {
            if(isChecked)
            {
                if(iIndex == -1)
                {
                    currDataInfo.push(mobile);

                    ids += sKid + ",";
                    names += sKname + ","; 
                }
            }
            else
            {
                if(iIndex > -1)
                {
                    currDataInfo.splice(iIndex, 1);
                }
                ids = ids.replace(sKid + "," ,''); 
                names = names.replace(sKname + "," ,'');
            }
        }
    }
</script>
</html>
